package org.jackysoft.quartz;

import java.util.Calendar;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jackysoft.service.FileDataService;
import org.jackysoft.util.DateUtils;
import org.springframework.stereotype.Component;

//@Component("runMeTask")
public class CleanupFilesTask {
	protected final Log log = LogFactory.getLog(CleanupFilesTask.class);
	private Calendar updateDate;
	private FileDataService fileService;
	public void cleanUpFiles() {
		 int year = DateUtils.getYear(updateDate);
		 int month = DateUtils.getMonth(updateDate);
		 log.info("磁盘清理任务开始于  "+DateUtils.getShowedDateString(updateDate));
         this.fileService.clear(year, month);
         log.info("磁盘清理任务结束于 "+DateUtils.getShowedDateString(Calendar.getInstance()));
	}

	@PostConstruct
	public void init(){
		Calendar cal = Calendar.getInstance();
		cal.roll(Calendar.MONTH, -4);	
		this.setUpdateDate(cal);
	}

	@Resource
	public void setFileService(FileDataService fileService) {
		this.fileService = fileService;
	}
    
	public void setUpdateDate(Calendar updateDate) {		
		this.updateDate = updateDate;
	}


	
}
